<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="消息类型" prop="type">
        <el-select v-model="queryParams.type" placeholder="请选择消息类型">
          <el-option
            v-for="dict in dict.type.order_notice_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:ordernotice:edit']"
        >查看</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:ordernotice:remove']"
        >删除</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['business:ordernotice:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="ordernoticeList" @selection-change="handleSelectionChange">
<!--      <el-table-column type="selection" width="55" align="center" />-->
<!--      <el-table-column label="主键" align="center" prop="id" />-->
<!--      <el-table-column label="标题" align="center" prop="tilte" />-->
<!--      <el-table-column label="内容" align="center" prop="content" />-->
<!--      <el-table-column label="发送人" align="center" prop="sendUserId" />-->
<!--      <el-table-column label="接收人" align="center" prop="receiveUserId" />-->
<!--      <el-table-column label="是否已读" align="center" prop="isRead" />-->

      <el-table-column label="发送人" align="center" prop="sendId">
        <template slot-scope="scope">
          <span>{{ scope.row.sendUser &&   scope.row.sendUser.nickName }}</span>
        </template>
      </el-table-column>


      <el-table-column label="消息类型" align="center" prop="type">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.order_notice_type" :value="scope.row.type"/>
        </template>
      </el-table-column>
<!--      <el-table-column label="发单人金额" align="center" prop="fdMoney" />-->
<!--      <el-table-column label="代练师金额" align="center" prop="playMoney" />-->
<!--      <el-table-column label="手续费分配" align="center" prop="sxfType">-->
<!--        <template slot-scope="scope">-->
<!--          <dict-tag :options="dict.type.sxf_type" :value="scope.row.sxfType"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label=" 仲裁方式"align="center" prop="zcType">-->
<!--        <template slot-scope="scope">-->
<!--          <dict-tag :options="dict.type.zc_fee_type" :value="scope.row.zcType"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="打手选择的仲裁方式" align="center" prop="playZcType">-->
<!--        <template slot-scope="scope">-->
<!--          <dict-tag :options="dict.type.zc_fee_type" :value="scope.row.playZcType"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="发单人选择的仲裁费用" align="center" prop="fdZcType">-->
<!--        <template slot-scope="scope">-->
<!--          <dict-tag :options="dict.type.zc_fee_type" :value="scope.row.fdZcType"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="发单人意见" align="center" prop="fdYj">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.order_noitce_status" :value="scope.row.fdYj"/>
        </template>
      </el-table-column>
<!--      <el-table-column label="发单人意见时间" align="center" prop="fdYjDate" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.fdYjDate, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="打手意见" align="center" prop="playYj" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.order_noitce_status" :value="scope.row.playYj"/>
        </template>
      </el-table-column>
      <el-table-column label="发单人选择的仲裁费用支付方式" align="center" prop="fdZcType" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.zc_fee_type" :value="scope.row.fdZcType"/>
        </template>
      </el-table-column>
      <el-table-column label="打手选择的仲裁费用支付方式" align="center" prop="playZcType" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.zc_fee_type" :value="scope.row.playZcType"/>
        </template>
      </el-table-column>


<!--      <el-table-column label="打手意见时间" align="center" prop="payYjDate" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.payYjDate, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="担保人意见" align="center" prop="dbrYj">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.order_noitce_status" :value="scope.row.dbrYj"/>
        </template>
      </el-table-column>
<!--      <el-table-column label="担保人意见时间" align="center" prop="dbrYjDate" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.dbrYjDate, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="担保人1意见" align="center" prop="dbrYj1">-->
<!--        <template slot-scope="scope">-->
<!--          <dict-tag :options="dict.type.order_noitce_status" :value="scope.row.dbrYj1"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="担保人1意见时间" align="center" prop="dbrYj1Date" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.dbrYj1Date, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="担保人2意见" align="center" prop="dbrYj2">-->
<!--        <template slot-scope="scope">-->
<!--          <dict-tag :options="dict.type.order_noitce_status" :value="scope.row.dbrYj2"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="担保人2意见时间" align="center" prop="dbrYj2Date" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.dbrYj2Date, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="失败方 1 发单人 2打手" align="center" prop="failureType" />-->
<!--      <el-table-column label="自我介绍" align="center" prop="userInfo" />-->
<!--      <el-table-column label="凭证文件" align="center" prop="pzFile" />-->
<!--      <el-table-column label="订单Id" align="center" prop="orderId" />-->
<!--      <el-table-column label="备注" align="center" prop="remark" />-->
      <el-table-column label="创建时间" align="center" prop="createTime" width="180"></el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:ordernotice:edit']"
          >查看</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:ordernotice:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改订单消息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
  <el-form ref="form" :model="form" :rules="rules" label-width="200px">
  <el-row :gutter="20">
    <el-col :span="12">
      <el-form-item label="消息类型" prop="type">
        <el-select v-model="form.type" placeholder="请选择消息类型">
          <el-option
            v-for="dict in dict.type.order_notice_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-col>

  </el-row>

  <el-row :gutter="20">
    <el-col :span="12">
      <el-form-item label="发单人金额" prop="fdMoney">
        <el-input v-model="form.fdMoney" placeholder="请输入发单人金额" />
      </el-form-item>
    </el-col>
    <el-col :span="12">
      <el-form-item label="代练师金额" prop="playMoney">
        <el-input v-model="form.playMoney" placeholder="请输入代练师金额" />
      </el-form-item>
    </el-col>
  </el-row>
    <el-row :gutter="20">
    <el-col :span="12">
      <el-form-item label="手续费分配" prop="sxfType">
        <el-select v-model="form.sxfType" placeholder="请选择手续费分配">
          <el-option
            v-for="dict in dict.type.sxf_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-col>
  </el-row>

  <el-row :gutter="20">
    <el-col :span="12">
      <el-form-item label="仲裁方式" prop="zcType">
        <el-select v-model="form.zcType" placeholder="请选择仲裁方式">
          <el-option
            v-for="dict in dict.type.zc_fee_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-col>

  </el-row>

  <el-row :gutter="20">
    <el-col :span="12">
      <el-form-item label="发单人选择的仲裁费用" prop="fdZcType">
        <el-select v-model="form.fdZcType" placeholder="请选择发单人选择的仲裁费用">
          <el-option
            v-for="dict in dict.type.zc_fee_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-col>
    <el-col :span="12">
      <el-form-item label="打手选择的仲裁方式" prop="playZcType">
        <el-select v-model="form.playZcType" placeholder="请选择打手选择的仲裁方式">
          <el-option
            v-for="dict in dict.type.zc_fee_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-col>
  </el-row>

    <el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="发单人意见" prop="fdYj">
          <el-select v-model="form.fdYj" placeholder="请选择发单人意见">
            <el-option
              v-for="dict in dict.type.order_noitce_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-col>
    </el-row>


  <el-row :gutter="20">
<!--    <el-col :span="12">-->
<!--      <el-form-item label="发单人意见时间" prop="fdYjDate">-->
<!--        <el-date-picker clearable-->
<!--          v-model="form.fdYjDate"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择发单人意见时间">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--    </el-col>-->
    <el-col :span="12">
      <el-form-item label="打手意见" prop="playYj">
        <el-select v-model="form.playYj" placeholder="请选择发单人意见">
          <el-option
            v-for="dict in dict.type.order_noitce_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-col>
  </el-row>

  <el-row :gutter="20">
<!--    <el-col :span="12">-->
<!--      <el-form-item label="打手意见时间" prop="payYjDate">-->
<!--        <el-date-picker clearable-->
<!--          v-model="form.payYjDate"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择打手意见时间">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--    </el-col>-->
    <el-col :span="12">
      <el-form-item label="担保人意见" prop="dbrYj">
        <el-select v-model="form.dbrYj" placeholder="请选择担保人意见">
          <el-option
            v-for="dict in dict.type.order_noitce_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-col>
  </el-row>

  <el-row :gutter="20">
    <el-col :span="12">
<!--      <el-form-item label="担保人意见时间" prop="dbrYjDate">-->
<!--        <el-date-picker clearable-->
<!--          v-model="form.dbrYjDate"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择担保人意见时间">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
    </el-col>
    <el-col :span="12">
      <el-form-item label="担保人1意见" prop="dbrYj1">
        <el-select v-model="form.dbrYj1" placeholder="请选择担保人1意见">
          <el-option
            v-for="dict in dict.type.order_noitce_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-col>
  </el-row>

  <el-row :gutter="20">
<!--    <el-col :span="12">-->
<!--      <el-form-item label="担保人1意见时间" prop="dbrYj1Date">-->
<!--        <el-date-picker clearable-->
<!--          v-model="form.dbrYj1Date"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择担保人1意见时间">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--    </el-col>-->
    <el-col :span="12">
      <el-form-item label="担保人2意见" prop="dbrYj2">
        <el-select v-model="form.dbrYj2" placeholder="请选择担保人1意见">
          <el-option
            v-for="dict in dict.type.order_noitce_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-col>
  </el-row>

  <el-row :gutter="20">
<!--    <el-col :span="12">-->
<!--      <el-form-item label="担保人2意见时间" prop="dbrYj2Date">-->
<!--        <el-date-picker clearable-->
<!--          v-model="form.dbrYj2Date"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择担保人2意见时间">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--    </el-col>-->
    <el-col :span="24">
      <el-form-item label="自我介绍" prop="userInfo">
        <el-input v-model="form.userInfo" placeholder="请输入自我介绍" />
      </el-form-item>
    </el-col>
  </el-row>

  <el-row :gutter="20">
    <el-col :span="24">
      <el-form-item label="凭证文件" prop="pzFile">
        <file-upload v-model="form.pzFile"/>
      </el-form-item>
    </el-col>
  </el-row>
</el-form>

      <div slot="footer" class="dialog-footer">
<!--        <el-button type="primary" @click="submitForm">确 定</el-button>-->
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listOrdernotice, getOrdernotice, delOrdernotice, addOrdernotice, updateOrdernotice } from "@/api/business/ordernotice";
import {send} from "q";

export default {
  name: "Ordernotice",
  dicts: ['order_noitce_status', 'sxf_type', 'order_notice_type', 'zc_fee_type'],
  props: {
    orderId: null
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单消息表格数据
      ordernoticeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        tilte: null,
        content: null,
        sendUserId: null,
        receiveUserId: null,
        isRead: null,
        type: null,
        operType: null,
        isNeedOper: null,
        operUserId: null,
        operData: null,
        fdMoney: null,
        playMoney: null,
        sxfType: null,
        zcType: null,
        playZcType: null,
        fdZcType: null,
        fdYj: null,
        fdYjDate: null,
        playYj: null,
        payYjDate: null,
        dbrYj: null,
        dbrYjDate: null,
        dbrYj1: null,
        dbrYj1Date: null,
        dbrYj2: null,
        dbrYj2Date: null,
        failureType: null,
        userInfo: null,
        pzFile: null,
        orderId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    send,
    /** 查询订单消息列表 */
    getList() {
      this.loading = true;
      if(this.orderId){
        this.queryParams.orderId = this.orderId;
      }
      listOrdernotice(this.queryParams).then(response => {
        this.ordernoticeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        tilte: null,
        content: null,
        sendUserId: null,
        receiveUserId: null,
        isRead: null,
        type: null,
        operType: null,
        isNeedOper: null,
        operUserId: null,
        operData: null,
        fdMoney: null,
        playMoney: null,
        sxfType: null,
        zcType: null,
        playZcType: null,
        fdZcType: null,
        fdYj: null,
        fdYjDate: null,
        playYj: null,
        payYjDate: null,
        dbrYj: null,
        dbrYjDate: null,
        dbrYj1: null,
        dbrYj1Date: null,
        dbrYj2: null,
        dbrYj2Date: null,
        failureType: null,
        userInfo: null,
        pzFile: null,
        orderId: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加订单消息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getOrdernotice(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "查看订单消息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateOrdernotice(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrdernotice(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除订单消息编号为"' + ids + '"的数据项？').then(function() {
        return delOrdernotice(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/ordernotice/export', {
        ...this.queryParams
      }, `ordernotice_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
